package com.upay.android.client.validation;

import static com.upay.android.client.helper.Keys.EMAIL_VALIDATION;

import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class EmailValidator {
	
	/* ---- Constants ---- */
    private static final String EMAIL_PATTERN = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
    
    /* ---- Instance Variables ---- */
    private Pattern pattern;
    private Matcher matcher;
 
    /* ---- Constructors ---- */
    public EmailValidator() {
        pattern = Pattern.compile(EMAIL_PATTERN);
    }

	/* ---- Business Methods ---- */


	public void validate(String email, Map<String, String> errors) {
		
		
		matcher = pattern.matcher(email);
        if (!matcher.matches()) {
        	errors.put(EMAIL_VALIDATION, "Invalid email address");
        }
		
	}
    
    /* ---- Getters and Setters ---- */


}
